#include<iostream>

using namespace std;
// zdl: 这道题目其实就是一道简单的线性dp

int n, k;
const int N = 1e4 + 10;
int a[N];
int f[N];
int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
// zdl:: 直接使用线性dp
    for (int i = 1; i <= n; i++)
    {
        int t = a[i];
        for (int j = i - 1; j >= 0 && i - j <= k; j--)
        {
            f[i] = max(f[i], f[j] + t * (i - j));
            t = max(t, a[j]);
        }
    }

    cout << f[n] << endl;
    return 0;
}